<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content-header"><h1>计划删除审核</h1></section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>物料描述</label>
                                    <input type="text" name="rppMatDesc" class="form-control" placeholder="请输入提报物料描述">
                                </div>
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="rppProjectCode" class="form-control" placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="rppProjectName" class="form-control" placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>计划员</label>
                                    <input type="text" name="rppPlanner" class="form-control" placeholder="请输入计划员">
                                </div>
                                <div class="form-group">
                                    <label>提报状态</label>
                                    <select name="rppUseStock" class="form-control">
                                        <option value="1">使用库存</option>
                                        <option value="2">正常提报</option>
                                        <option value="3">暂不提报</option>
                                        <option value="" selected="">全部</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>分类</label>
                                    <select name="rppTypeId" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option th:each="type : ${categories}" th:value="${type.dicId}"
                                                th:text="${type.dicName}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>生产状态</label>
                                    <select name="rppProjectState" class="form-control"
                                            style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width:auto!important;">
                                        <option value="" selected="selected">全部</option>
                                        <option value="-1">无状态</option>
                                        <option value="1">未开始</option>
                                        <option value="2">执行中</option>
                                        <option value="3">已完成</option>
                                        <option value="4">取消</option>
                                        <option value="5">暂缓</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>单据状态</label>
                                    <select name="rppStatus" class="form-control">
                                        <option value="">全部</option>
                                        <option value="1" selected="selected">未审核</option>
                                        <option value="-3">已删除</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>指定状态</label>
                                    <select name="rppIsFlag" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="1">已指定</option>
                                        <option value="2">未指定</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>提报日期</label>
                                    <input type="text" class="form-control datepicker" name="startTime"
                                           readonly="readonly"/>
                                    <span> 至 </span>
                                    <input type="text" class="form-control datepicker" name="endTime"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>

                        </div>
                    </form>
                    <!--<div class="row" id="toolbar">
                        <div class="form-inline">
                            <a shiro:hasPermission="buy:planedit:edit" href="javascript:void(0);" class="btn btn-success pull-right" style="margin-right: 10px" onclick="commitAll()">
                                <span class="Bold">全部提交</span>
                            </a>
                        </div>
                    </div>-->
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    /** 表格 */
    var table;
    var reportState = ['', '使用库存', '正常提报', '暂不提报','甲供'];
    var projectState = ['无状态', '执行中', '未开始', '暂缓', '已完成','取消'];
    var colors = ['', "label-warning", "label-default", "label-danger", "label-success"];
    var colors1 = ['', "label-warning", "label-info", "label-primary", "label-success"];


    /** 审核通过 - 真删除 */
    function deleteReportPlan(id) {
        js.confirmPost({
            content: "审核通过将永久删除数据，确认删除吗？",
            url: ctx + "buy/planDelCheck/delete",
            data: {
                id: id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }

    /** 批量提交提报计划 */
    function deleteAll() {
        var arr = js.table.selectColumns(table, "rppId");
        if (arr.length < 1) {
            js.modal.warning("请选择要提交的计划");
            return;
        }
        js.post({
            url: ctx + "buy/planDelCheck/commitAll",
            data: {
                rppIds: js.table.selectColumns(table, "rppId")
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }

    /** 驳回删除 */
    function cancelReportPlan(id) {
        js.confirmPost({
            content: "确认驳回吗？",
            url: ctx + "buy/planDelCheck/cancel",
            data: {
                id: id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }

    $(function () {
        $("title").html($("title").html() + " —— 计划删除审核");
        /** 初始化表格 */
        table = js.table.init({
            showColumns: true,
            showExport: false,
            paginationVAlign: 'both',
            url: ctx + "buy/planDelCheck/list",
            columns: [
                /*{
                    checkbox: true,
                    width: '30px',
                    formatter: function (value, row, index) {
                        // 正常提报并且数据正常状态可以提交选择
                        if (row.rppStatus === 2 && row.rppUseStock === 2) {
                            return {disabled: false}
                        } else {
                            return {disabled: true}
                        }
                    }
                },*/
                {
                    title: '序号', field: 'id', width: '50px',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: "计划员", field: 'rppPlanner'},
                {title: "物料描述", field: 'rppMatDesc'},
                {title: "数量", field: 'rppNum'},
                /*              { title: "实用", field: 'rppRealNum'},
                              { title: "余量", field: 'rppOverNum'},*/
                {title: "单位", field: 'rppUnit'},
                {title: "标准号", field: 'rppStandardNo'},
                {title: "分类", field: 'rppTypes'},
                {title: "品牌", field: 'rppBrand'},
                {title: "备注", field: 'rppRemark', width: '60px'},
                {title: "项目编号", field: 'rppProjectCode'},
                {title: "项目名称", field: 'rppProjectName'},
                {title: "原因", field: 'rppDelReason'},
                // { title: "联系人", field: 'rppDesigner'},
                {
                    title: "提报状态", field: 'rppUseStock',
                    formatter: function (value, row, index) {
                        if (value) {
                            return '<span class="badge ' + colors1[value] + '">' + reportState[value] + '</span> ';
                        }
                    }
                },
                {
                    title: "生产状态", field: 'rppProjectStateStr',
                    formatter: function (value, row, index) {
                        return value;
                    }
                },
                {title: "计划号", field: 'rppPlanNo'},
                {title: "提报日期", field: 'rppCreateTime', width: '90px'},
                {
                    title: "操作",
                    width: '110px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP('buy:plancheck:edit') && row.rppExtendUrl) {
                            actions.push('<a class="btn btn-primary btn-xs" href="/buy/getReportPlanList/downloadById/' + row.rppId + '"><i class="glyphicon glyphicon-download-alt"></i> 下载</a> ');
                        }
                        if (row.rppStatus != -3) {
                            if (hasP('buy:plancheck:edit')) {
                                actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="deleteReportPlan(' + row.rppId + ')"> 审核</a> ');
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="cancelReportPlan(' + row.rppId + ')"> 驳回</a> ');
                            }
                        }
                        return actions.join('');
                    }
                }
            ]
        });

        /** 表格搜索 */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

    });

</script>
</body>
</html>
